<?php
session_start();
include "../common/db.inc";
if($_SESSION["field_category"] == false)
{
	$arrField = array();
	$arrCategory = array();
	$conn = new mysqli($host, $username, $password, $dbname);	
	$conn->query("set names 'utf8'");
	$listfield = $conn->query("call sp_GetAllField()");
	while($field = $listfield->fetch_row())
	{
		$arrField[$field[0]] = $field[1];
		$arr = array();
		$conn->close();
		$conn = new mysqli($host, $username, $password, $dbname);	
		$conn->query("set names 'utf8'");
		$listcategory = $conn->query("call sp_GetCategoryByField($field[0])");
		while($category = $listcategory->fetch_row())
		{
			$arr[$category[0]] = $category[1];
		}
		$arrCategory[] = $arr;		
	}		
	$conn->close();
	$_SESSION['field_category'] = array($arrField, $arrCategory);
}
?>
<div id="content_left">
    <div class="content_left_section">
        <h1>Danh Mục</h1>
		<?php	
		$in_field = $_GET['field'];
		$in_cat = $_GET['category'];
		$arrField = $_SESSION['field_category'][0];
		$arrCategory = $_SESSION['field_category'][1]; 
		
		echo "<div class='menu_list'>";
		$i = 0;
		foreach($arrField as $fieldkey=>$fieldvalue)
		{
			if($in_field == $fieldkey)
			{
				echo "<div class='menu_head minus'><span>$fieldvalue</span></div>";
				echo "<div class='submenu' style='display:block;'>";
			}
			else
			{
				echo "<div class='menu_head plus'><span>$fieldvalue</span></div>";
				echo "<div class='submenu'>";
			}
			echo "<ul>";
			foreach($arrCategory[$i] as $catkey=>$catvalue)
			{
				if($in_cat == $catkey)
					echo "<li><a class='active_cat' href='showbook.php?field=$fieldkey&category=$catkey'>$catvalue</a></li>";
				else
					echo "<li><a href='showbook.php?field=$fieldkey&category=$catkey'>$catvalue</a></li>";
			}
			echo "</ul>";
			echo "</div>";
			$i++;
		}
		echo "</div>";
		
		?>
	</div>
</div>